window.onload =function (){
    showLoginInfo();
    showProduct(1);
}

function showProduct(pageNo){
    axios.get("/product/findByItem",{
        params:{
            pageNo,
            name:$("name").value,
            startDate:$("startDate").value,
            endDate:$("endDate").value
        }
    }).then(e=>{
        var info = e.data;
        //显示商品数据
        var str="";
        for (var i=0;i<info.records.length;i++){
            var obj = info.records[i];
            str +=`<div>
        <img src="/productImage/${obj.imgPath}" width="200" height="200"><br>
        
        ${obj.name}<br>单价:${obj.price}<br>已售出数量:${obj.num}件<br><a href="/custom/shop.html?productId=${obj.id}">购买</a>
        <a href="/product.html?productId=${obj.id}">查看</a>
        </div>`
        }
        $("productDiv").innerHTML = str;

        var cutStr = "";
        for (var i=1;i<info.pages;i++){
            cutStr+=`<a href="javascript:showProduct(${i})">${i}</a>`
        }
        $("cutPageDiv").innerHTML = cutStr;

    });



}

/**
 * 得到登录用户
 */
function showLoginInfo(){
    axios.get("/user/getLoginUser",null).then(e=>{
        var info = e.data;
        if (info != null && info !=''){
            $("infoDiv").innerHTML ="欢迎光临: " +info.name;
        }else{
            $("infoDiv").innerHTML ="你好请先<a href='/login.html'>登录</a>";
        }

    })
}